﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinqToTwitter;

namespace Twitter
{
    public partial class AmisTweets : System.Web.UI.Page
    {
        private String userId;
        private String friendId;
        public LinqToTwitter.User user
        {
            set
            { 
                
            }
            get 
            {
                Util.UserTweets util = new Util.UserTweets(Request, Response, userId);

                return util.getUser(Session["auth"] as WebAuthorizer, friendId);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {          
            Util.Authentification authen = new Util.Authentification();
            Boolean b = authen.isAuthentificated(Request, Response);

            if (!b)
                authen.auth.BeginAuthorization(Request.Url);
            else
            {
                Session["auth"] = authen.auth;
            }

            userId   = authen.auth.UserId;
            friendId = Request.Params["userid"];
        }

        public IEnumerable<Status> getFriendTweets()
        {
            Util.UserTweets friendTweets = new Util.UserTweets(Request, Response, userId);

            return friendTweets.getFriendTweets(Session["auth"] as WebAuthorizer, friendId);
        }

        protected void saveUserClicked(object sender, EventArgs e)
        {
            this.saveResult.Text = "";
            Util.UserTweets persist = new Util.UserTweets(Request, Response, userId);
            persist.PersistTweets(Session["auth"] as WebAuthorizer, persist.getUser(Session["auth"] as WebAuthorizer, friendId), Connexion.getConnectedUserName());
            this.saveResult.Text = "Les données ont été bien enregistrées"; 
        }




    }
}